package com.wanmait.wisdom.manage.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wanmait.wisdom.entity.Parking;

import com.wanmait.wisdom.manage.service.ManageParkingService;
import com.wanmait.wisdom.mapper.ParkingMapper;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.TimeUnit;

@Service
public class ManageParkingServiceImpl extends ServiceImpl<ParkingMapper, Parking> implements ManageParkingService {
    @Resource
    private ParkingMapper parkingMapper;
    @Resource
    private RedisTemplate<String,Object> redisTemplate;


    @Override
    @Cacheable("parkingList")
    public List<Parking> findAllParking() {
        LambdaQueryWrapper<Parking> queryWrapper = new LambdaQueryWrapper<>();
        redisTemplate.opsForValue().set("parkingList",parkingMapper.selectList(queryWrapper.orderByAsc(Parking::getSpaceNumber)),1, TimeUnit.HOURS);
        return parkingMapper.selectList(queryWrapper.orderByAsc(Parking::getSpaceNumber));
    }


}
